<template>
	<view >
		<!-- <view class="" @click="copy(out_trade_no)">{{out_trade_no}}</view> -->
		
		<!-- 盲盒支付 -->
		<blind-box-payment v-if="ysSkipType == 1" :orderId='orderId'></blind-box-payment>  
		<!-- 转赠支付 -->
		<subgift v-else-if="ysSkipType == 3" :orderId='orderId'></subgift>
		<!-- 权益卡支付 -->
		<equity-payment v-else-if="ysSkipType == 2" :orderId='orderId' :outStatus='outStatus'></equity-payment>
		
	</view>
</template>

<script>
    var goldPlan = require('../../../../common/jgoldplan-1.0.0.js');
    import api from '@/api/api.js'
	import blindBoxPayment from './blindBoxPayment'
	import equityPayment from './equityPayment'
	import subgift from './subgift'
	export default {
		components: {
			blindBoxPayment,
			equityPayment,
			subgift
		},
		data() {
			return {
				orderId:'', //订单id
				out_trade_no:'', //第三方支付 商户号Id
				outStatus:1, //微信支付 1 第三方支付 2
				num:0,
				ysSkipType:null, //1 盲盒 2数字权益卡 3 转赠
			}
		},
		onLoad(e) {
			// this.ysSkipType = 1
			if(e.out_trade_no != undefined){
				// this.out_trade_no = e.out_trade_no
				this.num = 0
				this.getYsResult(e.out_trade_no)
				this.outStatus = 2
			}
			else{
				this.orderId = e.orderId
				this.outStatus = 1
				this.ysSkipType = 2
				// this.getPayResult()
			}
			
		},
		onReady() {
			let mchData = {
				action: 'onIframeReady',
				displayStyle: 'SHOW_CUSTOM_PAGE',
				height:960
			};
			let postData = JSON.stringify(mchData);
			parent.postMessage(postData, 'https://payapp.weixin.qq.com');
		},
		methods: {
			async getYsResult(data){
				uni.showLoading({ title:'加载中' })
				try{
					var ysResult = await api.getYsResult(data)
					if(ysResult.result != ""){
						  uni.hideLoading()
						  this.orderId = ysResult.result.orderId; //商户订单号
						  this.ysSkipType = ysResult.result.ysSkipType; //商户订单号
					 }else{
						if(this.num < 30 ){
							setTimeout(res=>{
							   this.getYsResult(data)
							   this.num++
							},1000)
						}else{
							uni.showToast({
								title:'请求超时！',
								icon:'none'
							})
						}
					}
				}catch{
					uni.hideLoading()
				}
			},
			copy(text){
				if(text != ''){
					var _this = this
					 _this.$copyText(text).then(
			            res => {
			              uni.showToast({
			                title: '复制成功',
			                icon: 'none'
			              })
			            }
			          )
				}
			},
		}
	}
</script>

<style scoped>

</style>
